//
//  MainTabBar.m
//  OC-LBWeibo
//
//  Created by 李博 on 15/6/24.
//  Copyright © 2015年 libo. All rights reserved.
//

#import "MainTabBar.h"

@interface MainTabBar()

//@property(nonatomic,assign)int buttonCount;

@end

@implementation MainTabBar

int buttonCount = 5;

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat w = self.bounds.size.width / buttonCount;
    CGRect rect = CGRectMake(0, 0, w, self.bounds.size.height);
    int index = 0;
    for (UIView *v in self.subviews) {
        
        if ([v isKindOfClass:[UIControl class]] && ![v isKindOfClass:[UIButton class]]) {
            v.frame = CGRectOffset(rect, index * w, 0);
            index += index == 1? 2 : 1;
        }
    }
    //设置加号按钮的位置
    self.compoesButton.frame = CGRectOffset(rect, 2 * w, 0);
}



- (UIButton *)compoesButton
{
    if (_compoesButton == nil) {
        UIButton *btn = [[UIButton alloc]init];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        
        [self addSubview:btn];
        _compoesButton = btn;
    }
    
    return _compoesButton;
}


@end
